const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function choujiang(array,fuc){
  console.log(array);
  var that = this;
  this.j_bushu = 10; // 在10的时候开始加速
  if (array.j_bushu) {
    this.j_bushu = array.j_bushu;
  }
  this.j_times = 20; //每次的减少时间
  if (array.j_times) {
    this.j_times = array.j_times;
  }
  this.times = 500; //基础的跳转时间
  if (array.times) {
    this.times = array.times;
  }
  this.zhong = 100; // 总共的步数
  if (array.zhong) {
    this.zhong = array.zhong;
  }
  this.dangqian = 0;
  this.func = '';
  if(fuc){
    this.func = fuc;
  }




  function start() {
    // console.log('开始执行了')
    that.dangqian++;
    // console.log(that.dangqian)
    // console.log(that.zhong)
    if (that.dangqian <= that.zhong) {
      if (that.dangqian <= that.j_bushu) {
        that.times = that.times - that.j_times;
      }
      if (that.dangqian >= that.zhong - that.j_bushu) {
        that.times = that.times + that.j_times;
      }
      // console.log(that.times)
      //if (that.func) {
        if (that.dangqian == that.zhong){
          that.func(that.dangqian,true);
        }else{
          that.func(that.dangqian, false);
        }
      //}








      setTimeout(start, that.times);
    }
  }

  start();
}
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
  choujiang: choujiang
}
